import 'package:flutter/material.dart';

class MyApp3 extends StatefulWidget {
  const MyApp3({super.key});

  @override
  State<MyApp3> createState() => _MyApp3State();
}

class _MyApp3State extends State<MyApp3> {
  //状态变量(数据变化,视图会更新)
  int age = 18;
  String name = '张三';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          '有状态组件',
          style: TextStyle(color: Colors.white, fontSize: 20),
        ),
        backgroundColor: Colors.pink,
        centerTitle: true,
      ),
      body: Center(
        child: Text(
          '我叫$name,今年$age',
          style: TextStyle(fontSize: 20, color: Colors.red),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          //其中setState()方法会重新调用build方法
          setState(() {
            age++;
            print(age);
          });
        },
        child: const Icon(Icons.add),
      ),
    );
  }
}
